package com.neuedu.api.wrapclass;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/229:00
 */
public class Person {

    //1 属性
    private String name;
    private Integer age;


    //2 构造方法
    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }


    //3 setter getter
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }


    //toString
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    public static void main(String[] args) {



        Person p1 = new Person();
        p1.setAge(0);

        System.out.println(p1);

        //1 基础类型 --->包装类
        /**
         * byte short int long    Byte  Short Integer Long
         * float double           Float Double
         * char                   Character
         * boolean                Boolean
         */

        int num = 100;
        double num2 = 3.14;

        //1.1 使用构造方法
        Integer  intWrap1 = new Integer(num);
        Double doubleWrap1 = new Double(num2);
       //.....

        //1.2 使用静态的valueof方法
        Integer   intWrap2= Integer.valueOf(num);
        Double   doubleWrap2= Double.valueOf(num2);
        //.......


        //2 从包装类型 转基础类型
        int toIntNum = intWrap1.intValue();
        double toDoubleNum = doubleWrap1.doubleValue();




        //3 从基础类型 转换成包装类  valueOf
        int numa = 150;
        String strNum  = String.valueOf(numa);

        byte b1 = 102;
        String numToString = String.valueOf(b1);

        System.out.println("strNum+100 : "+(strNum+100));

        String numaToString2 = numa+"";



        //4字符串 转  基础类型   ZXXXX.parseXXX
        String numWithString = "3.14";
        //错误的  转换的时候不能出现非数字
        // String numWithStringInt = "15000abcdef";
        String numWithStringInt = "15000";
        double doubleFromString = Double.parseDouble(numWithString);



        //5 字符串转包装类型    valueOf
        Double aDouble = Double.valueOf(numWithString);
        Integer aIngeter = Integer.valueOf(numWithStringInt);

        System.out.println("aIngeter = " + aIngeter);


        //6 包装类型转成 字符串

        Integer wrapInteger = new Integer(100);
        System.out.println("wrapInteger.toString().length() = " + wrapInteger.toString().length());

    }
}
